#include <stdio.h>
#include <curl/curl.h>
 
void usage(char * str) {
	printf("Usage:\r\n");
	printf("%s \"count=[count_of_plate]&num=[num1,num2,...]&color=[color1,color2,...]\"\r\n",str);
	printf("Example:\r\n");
	printf("%s \"count=1&num=粤A·RM520&color=blue\"\r\n",str);
	printf("%s \"count=2&num=粤A·RM520,粤T·1234F&color=blue,yellow\"\r\n",str);
	printf("color: yellow,blue,green\"\r\n");
}

int main(int argc,char **argv)
{
  CURL *curl;
  CURLcode res;
  if ( argc != 2) {
          usage(argv[0]);
	  return -1;
  }
  /* In windows, this will init the winsock stuff */
  curl_global_init(CURL_GLOBAL_ALL);
 
  /* get a curl handle */
  curl = curl_easy_init();
  if(curl) {
    /* First set the URL that is about to receive our POST. This URL can
       just as well be a https:// URL if that is what should receive the
       data. */
    curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1:5000/license_plate");
    /* Now specify the POST data */
    //curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "num=12345");
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, argv[1]);
 
    /* Perform the request, res will get the return code */
    res = curl_easy_perform(curl);
    /* Check for errors */
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));
 
    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  curl_global_cleanup();
  return 0;
}
